package cn.lanqiao.springbootproject.consumer;

import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Log4j2
@Component
@RabbitListener(queues = "phoneQueue")
public class PhoneConsumer {

    /**
     * 消息消费
     * @RabbitHandler 代表此方法为接受到消息后的处理方法
     */
    @RabbitHandler
    public void received(String msg) {
        try {
            Thread.sleep(2000L); // 模拟处理需要2秒
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("[PhoneQueue] received message: {}", msg);
    }

}
